import {AppDataSource} from './data-source'
import {User} from './entity/User'

AppDataSource.initialize().then(async () => {
    const queryBuilder = AppDataSource.manager.createQueryBuilder()
    queryBuilder.select(['user.firstName', 'user.lastName'])
    queryBuilder.addSelect('user.age')
    // 指定查询主表
    queryBuilder.from(User, 'user')
    queryBuilder.where('user.id = :id', {id:2})
    queryBuilder.andWhere('user.isActive=:isActive', {isActive: true})
    const user = await queryBuilder.getOne() // 查询一条
    const users = await queryBuilder.getMany() // 查询多条
    console.log('user', user)
    console.log('users', users)

    await queryBuilder.delete().from(User).where('id=:id', {id:2}).execute()
    
})